{ open Parser }

rule token = parse
  (* White space *)
  [' ' '\t' '\r' '\n']    { token lexbuf }

(* Begin comments *)
| "/*"	{ comment lexbuf }

(* Unary operators *)
| "!"	{ NOT}

(* Binary operators *)
| '+'	{ PLUS }
| '-'	{ MINUS }
| '*'	{ TIMES }
| '/'	{ DIVIDE }
| "<"	{ LT }
| ">"	{ GT }
| "=="	{ EQ }
| "!="	{ NEQ }
| "&&"	{ AND }
| "||"	{ OR }

(* Punctuation *)
| '='	{ ASSIGN }
| ','	{ COMMA }
| ';'	{ SEMI }
| '('	{ LPAREN }
| ')'	{ RPAREN }
| '{'	{ LBRACE }
| '}'	{ RBRACE }
| '['	{ LBRACK }
| ']'	{ RBRACK }

(* Keywords *)
| "if"		{ IF }
| "else"        { ELSE }
| "for"		{ FOR }
| "while"	{ WHILE }
| "until"	{ UNTIL }
| "add"		{ ADD }
| "minus"	{ MINUS }
| "count"	{ COUNT }
| "deal"	{ DEAL }
| "draw"	{ DRAW }
| "give"	{ GIVE }
| "query"	{ QUERY }
| "shuffle"	{ SHUFFLE }

(* Data types *)
| "card"	{ CARD }
| "deck"	{ DECK }
| "feature"	{ FEATURE }
| "featureList"	{ FEATURELIST }
| "hand"	{ HAND }
| "pile"	{ PILE }
| "player"	{ PLAYER }
| "playerList"	{ PLAYERLIST }
| "type"	{ TYPE }
| "typeList"	{ TYPELIST }

(* numbers/integers *)
| ['0'-'9']+ as num				    { NUM(int_of_string num) }

(* identifiers *)
| ['a'-'z''A'-'Z']['a'-'z''A'-'Z''0'-'9']* as id    { ID(id) }

(* illegal char *)
| _ as char	{ raise (Failure("Illegal character: " ^ Char.escaped char)) }

(* end of file *)
| eof	{ EOF }

(* end comments *)
and comment = parse
"*/"	{ token lexbuf } 
| _	{ comment lexbuf }
